package jerry.html.data.convertors;

import java.util.List;

import jerry.html.data.Score;
import jerry.html.data.Stuff;
import jerry.html.data.StuffType;
import jerry.html.events.CntrlPtCapEvtCapImpl;
import jerry.html.events.DomScoreEvtImpl;
import jerry.html.events.EvtCap;
import jerry.html.events.FlagCappedEvtCapImpl;
import jerry.html.events.FlagPickEvtCapImpl;
import jerry.html.events.FlgDrpEvtCapImpl;
import jerry.html.events.FlgRetEvtCapImpl;
import jerry.html.events.FlgRetTmoEvtCapImpl;
import jerry.html.events.FlgTakenEvtCapImpl;
import jerry.html.events.HeadShtEvtCapImpl;
import jerry.html.events.KillEvtCapImpl;
import jerry.html.events.SuicideEvtCapImpl;
import jerry.html.events.TeamKillEvtCapImpl;

/**
 * 
 * Used to convert score data
 * 
 * 
 * @author (h0t@_G0|i
 * 
 */
public class ScoreDataConvertor extends DataConvertor{

	@SuppressWarnings("unchecked")
	@Override
	public boolean convertData(List<? extends EvtCap> eventData) {
		boolean flag=false;
		
		if(dataType.equals(KillEvtCapImpl.class)) {
			for (KillEvtCapImpl evtCap : (List<KillEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.killerId, evtCap.killerWeapon,getStuffType(evtCap.killerWeapon));
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("KILL");
				score.setScoredOn(evtCap.getTimeStamp());
				score.setAgainst(getPlayer(evtCap.killedId));
				playerStuff.getScoreFromIt().add(score);
				playerStuff = getPlayerStuff(evtCap.killedId, evtCap.killerWeapon,getStuffType(evtCap.killerWeapon));
				score = new Score();
				score.setScore(1);
				score.setScoreType("DEATH");
				score.setScoredOn(evtCap.getTimeStamp());
				score.setAgainst(getPlayer(evtCap.killerId));
				playerStuff.getScoreFromIt().add(score);
			}
			flag=true;
		}
		if(dataType.equals(SuicideEvtCapImpl.class)) {
			for (SuicideEvtCapImpl evtCap : (List<SuicideEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.playerId, evtCap.weapon,getStuffType(evtCap.weapon));
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("SUICIDE");
				score.setScoredOn(evtCap.getTimeStamp());
				playerStuff.getScoreFromIt().add(score);
			}
			flag=true;
		}
		if(dataType.equals(TeamKillEvtCapImpl.class)) {
			for (TeamKillEvtCapImpl evtCap : (List<TeamKillEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.killerId, evtCap.killerWeapon,getStuffType(evtCap.killerWeapon));
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("TEAMKILL");
				score.setScoredOn(evtCap.getTimeStamp());
				score.setAgainst(getPlayer(evtCap.killedId));
				playerStuff.getScoreFromIt().add(score);
				playerStuff = getPlayerStuff(evtCap.killedId, evtCap.killerWeapon,getStuffType(evtCap.killerWeapon));
				score = new Score();
				score.setScore(1);
				score.setScoreType("DEATH");
				score.setScoredOn(evtCap.getTimeStamp());
				score.setAgainst(getPlayer(evtCap.killerId));
				playerStuff.getScoreFromIt().add(score);
			}
			flag=true;
		}
		if(dataType.equals(DomScoreEvtImpl.class)) {
			for (DomScoreEvtImpl evtCap : (List<DomScoreEvtImpl>)eventData) {
				Score score = getGame().getTeamScore().get(evtCap.teamId);
				if(score == null || !score.getScoreType().equals("DOM")) {
					score = new Score();
					score.setScore((int)evtCap.score);
					score.setScoreType("DOM");
					score.setScoredOn(evtCap.getTimeStamp());
					getGame().getTeamScore().put(evtCap.teamId,score);
				} else {
					score.setScore((int)evtCap.score + score.getScore());
				}
			}
			flag=true;
		}
		if(dataType.equals(HeadShtEvtCapImpl.class)) {
			for (HeadShtEvtCapImpl evtCap : (List<HeadShtEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.killerId, "DECAPITATOR",StuffType.SPECIAL);
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("HEADSHOT");
				score.setScoredOn(evtCap.getTimeStamp());
				score.setAgainst(getPlayer(evtCap.killedId));
				playerStuff.getScoreFromIt().add(score);
			}
			flag=true;
		}
		if(dataType.equals(CntrlPtCapEvtCapImpl.class)) {
			for (CntrlPtCapEvtCapImpl evtCap : (List<CntrlPtCapEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.playerId, evtCap.pointName,StuffType.SPECIAL);
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("CTRLPTCAP");
				score.setScoredOn(evtCap.getTimeStamp());
				playerStuff.getScoreFromIt().add(score);
			}
			flag=true;
		}
		if(dataType.equals(FlgTakenEvtCapImpl.class)) {
			for (FlgTakenEvtCapImpl evtCap : (List<FlgTakenEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.playerID, "FLAGGING",StuffType.SPECIAL);
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("TAKEN");
				score.setScoredOn(evtCap.getTimeStamp());
				playerStuff.getScoreFromIt().add(score);
			}
			flag=true;
		}
		if(dataType.equals(FlgDrpEvtCapImpl.class)) {
			for (FlgDrpEvtCapImpl evtCap : (List<FlgDrpEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.playerID, "FLAGGING",StuffType.SPECIAL);
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("DROP");
				score.setScoredOn(evtCap.getTimeStamp());
				playerStuff.getScoreFromIt().add(score);
			}
			flag=true;
		}
		if(dataType.equals(FlagCappedEvtCapImpl.class)) {
			for (FlagCappedEvtCapImpl evtCap : (List<FlagCappedEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.playerID, "FLAGGING",StuffType.SPECIAL);
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("CAPPED");
				score.setScoredOn(evtCap.getTimeStamp());
				playerStuff.getScoreFromIt().add(score);
				score = getGame().getTeamScore().get(evtCap.teamID);
				if(score == null || !score.getScoreType().equals("CAPPED")) {
					score = new Score();
					score.setScore(1);
					score.setScoreType("CAPPED");
					score.setScoredOn(evtCap.getTimeStamp());
					getGame().getTeamScore().put(evtCap.teamID,score);
				} else {
					score.setScore(1 + score.getScore());
				}
			}
			flag=true;
		}
		if(dataType.equals(FlagPickEvtCapImpl.class)) {
			for (FlagPickEvtCapImpl evtCap : (List<FlagPickEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.playerID, "FLAGGING",StuffType.SPECIAL);
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("PICK");
				score.setScoredOn(evtCap.getTimeStamp());
				playerStuff.getScoreFromIt().add(score);
			}
			flag=true;
		}
		if(dataType.equals(FlgRetEvtCapImpl.class)) {
			for (FlgRetEvtCapImpl evtCap : (List<FlgRetEvtCapImpl>)eventData) {
				Stuff playerStuff = getPlayerStuff(evtCap.playerID, "FLAGGING",StuffType.SPECIAL);
				Score score = new Score();
				score.setScore(1);
				score.setScoreType("RETURNED");
				score.setScoredOn(evtCap.getTimeStamp());
				playerStuff.getScoreFromIt().add(score);
			}
			flag=true;
		}
		if(dataType.equals(FlgRetTmoEvtCapImpl.class)) {
			for (FlgRetTmoEvtCapImpl evtCap : (List<FlgRetTmoEvtCapImpl>)eventData) {
				Score score = getGame().getTeamScore().get(evtCap.teamID);
				if(score == null || !score.getScoreType().equals("TIMEOUT_RETURN")) {
					score = new Score();
					score.setScore(1);
					score.setScoreType("TIMEOUT_RETURN");
					score.setScoredOn(evtCap.getTimeStamp());
					getGame().getTeamScore().put(evtCap.teamID,score);
				} else {
					score.setScore(1 + score.getScore());
				}
			}
			flag=true;
		}
		return flag;
	}

}
